<?php
/**
 * Ora 后台管理模块
 *  @author  lan7
 *  @copyright lan7.net
 *  @version 2.0
 */

if(!defined('IN_ORA')) {
	exit('Access Denied');
}
class admin extends mod{
	function admin(){
		parent::__construct();
		session_start();
		$this->setTplDir(PUBLIC_PATH);
		$this->setMsgTpl("admin/msg.html");
		if(!isset($_SESSION[$GLOBALS['ora_cfg']['sess_prefix']."admin"])){
			$this->showMsg("请先登录!",parse_uri("common-login"),1);
		}
	}

	/**
	 * 后台管理主页面
	 *
	 */
	function index(){
		$this->display("admin/index.html");
	}

	/**
	 * 左侧导航
	 *
	 */
	function left(){
		$this->display("admin/left.html");
	}
	
	function right(){
		$this->display("admin/right.html");
	}

	/**
	 * 管理默认页
	 *
	 */
	function main(){
		$this->display("admin/main.html");
	}

	/**
	 * 系统配置
	 *
	 */
	function config(){
		$this->assign('conf',$GLOBALS['ora_cfg']);
		$this->display("admin/config.html");
	}

	/**
	 * 管理帐号
	 *
	 */
	function account(){
		if(isset($_POST["submit"])){
			if(strlen(trim($_POST["passwd"]))==0){
				$this->showMsg("请输入当前密码!",$_SERVER["HTTP_REFERER"],1);
			}else if(md5($_POST["passwd"])!=$_SESSION[$GLOBALS['ora_cfg']['sess_prefix'].'admin']['passwd']){
				$this->showMsg("原始密码错误!",$_SERVER["HTTP_REFERER"],1);
			}else if(strlen(trim($_POST["npasswd"]))==0){
				$this->showMsg("请输入新密码!",$_SERVER["HTTP_REFERER"],1);
			}else if(strlen(trim($_POST["npasswd1"]))==0){
				$this->showMsg("确认密码不能为空!",$_SERVER["HTTP_REFERER"],1);
			}else if($_POST["npasswd"]!=$_POST["npasswd1"]){
				$this->showMsg("两次密码不一致!",$_SERVER["HTTP_REFERER"],1);
			}else{
				$sql = "update ".tn('members')." set passwd = '".md5($_POST['npasswd'])."' where uname = '".$_SESSION[$GLOBALS['ora_cfg']['sess_prefix']."admin"]['uname']."'";
				if($this->db->query($sql)){
					$msg['result'] = "操作成功!";
					unset($_SESSION[$GLOBALS['ora_cfg']['sess_prefix']."admin"]);
					$this->showMsg("操作成功,请重新登录!",parse_uri("common-login"),true);
				}
			}
		}
		$this->display("admin/account.html");
	}

	/**
	 * 清除系统缓存
	 *
	 */
	function clc(){
		io::removeDir(ROOT_PATH."archive");
		io::removeDir(ROOT_PATH."cache");
		$this->showMsg("缓存清除成功!",parse_uri("admin-main|true"),1);
	}

	/**
	 * 文件上传
	 *
	 */
	function upload(){
		$s = "";
		if(isset($_POST['submit'])){
			if($_FILES["userfile"]['error'][0]!=4){
				import("lib.upload");
				$up = new Upload("jpg|gif|png");
				if(!$up->errInfo){
					$img = $up->files[0]["urlPath"];
				}
			}
			if(isset($img)&&isset($GLOBALS['_param']['mth'])){
				$s = "<script>parent.".$GLOBALS['_param']['mth']."('$img');</script>";
			}
		}
		$GLOBALS['tpl']->assign('purl',get_url());
		$GLOBALS['tpl']->assign("js",$s);
		$GLOBALS['tpl']->display('admin/upload.html');
	}


}
?>